# encoding: utf-8
from importlib import _resolve_name

from app.extensions.api import api_v1
from flask_restplus_patched import Namespace

apis = {}


def init_app(app, **kwargs):
    from importlib import import_module

    for module_name in app.config['ENABLED_MODULES']:
        api = Namespace(module_name, description=module_name)
        api_v1.add_namespace(api)
        apis['%s.%s.resources' % (__name__, module_name)] = api

        import_module('.%s' % module_name, package=__name__).init_app(app,
                                                                      **kwargs)
        import_module('.%s.resources' % module_name, package=__name__)

